/**
 * MOTOR 2 - RAPID FLASH DYNAMICS
 * Copyright (c) 2006-2008 Michael Baczynski http://www.polygonal.de
 * 
 * Based on Box2D by Erin Catto, http://www.box2d.org
 *
 * This software is provided 'as-is', without any express or implied
 * warranty.  In no event will the authors be held liable for any damages
 * arising from the use of this software.
 * 
 * Permission is granted to anyone to use this software for any purpose,
 * including commercial applications, and to alter it and redistribute it
 * freely, subject to the following restrictions:
 * 
 * 1. The origin of this software must not be misrepresented; you must not
 * claim that you wrote the original software. If you use this software
 * in a product, an acknowledgment in the product documentation would be
 * appreciated but is not required.
 * 2. Altered source versions must be plainly marked as such, and must not be
 * misrepresented as being the original software.
 * 3. This notice may not be removed or altered from any source distribution.
 */
package de.polygonal.motor2.dynamics
{
	import de.polygonal.motor2.collision.shapes.data.ShapeData;	

	public class RigidBodyData
	{
		/* position, velocity, orientation */
		public var x:Number, vx:Number;
		public var y:Number, vy:Number;
		public var r:Number,  w:Number;
		
		public var allowSleep:Boolean;
		public var isSleeping:Boolean;
		public var linDamping:Number;
		public var angDamping:Number;
		public var preventRotation:Boolean;
		
		public var shapeDataList:ShapeData;
		
		public function RigidBodyData(x:Number = 0, y:Number = 0, r:Number = 0)
		{
			init();
			
			this.x = x;
			this.y = y;
			this.r = r;
		}
		
		public function init():void
		{
			x = y = r = vx = vy = w = .0;
			
			allowSleep      = true;
			isSleeping      = false;
			linDamping      = .0;
			angDamping      = .0;
			preventRotation = false;
			shapeDataList   = null;
		}
		
		public function move(x:Number, y:Number):void
		{
			this.x = x;
			this.y = y;
		}
		
		public function rotate(deg:Number):void
		{
			//wrap input angle to 0..2PI
			if (deg < 0)
				deg += 360;
			else
			if (deg > 360)
				deg -= 360;
			
			r = deg * (Math.PI / 180);
		}
		
		public function addShapeData(sd:ShapeData):void
		{
			if (sd == null) return;
			sd.next = shapeDataList;
			shapeDataList = sd;
		}
	}
}